package 复习.博客2.递归和回溯;

import java.util.ArrayList;

public class 没有重复数字的全排列 {
    ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
    ArrayList<Integer> list = new ArrayList<>();

    public ArrayList<ArrayList<Integer>> permute(int[] num) {
        backStacking(num,0);
        return lists;
    }

    public void backStacking(int[] num,int index){
        if(list.size() == num.length){
            lists.add(new ArrayList<>(list));
        }
        for (int i = 0; i < num.length; i++) {
            if(list.contains(num[i])) continue;
            list.add(num[i]);
            backStacking(num,i+1);
            list.remove(list.size() - 1);
        }
    }
}

/*
public class Solution {
    ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
    ArrayList<Integer> list = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> permute(int[] num) {
        backstacking(num);
        return lists;
    }

    public void backstacking(int[] nums){
        if(list.size() == nums.length){
            lists.add(new ArrayList<>(list));
        }

        for (int i = 0; i < nums.length; i++) {
                if(list.contains(nums[i])) continue;
                list.add(nums[i]);
                backstacking(nums);
                list.remove(list.size() - 1);
        }
    }
}
 */